from gui import gui
from gui . tests . create_widget_test_assistant import gui_create_widget_test_assistant

class application_window_fake :
    pass

class text_fake :
    def __init__ ( self ) :
        self . _configure = None
        self . _insert = None
        self . _mark_call_history = [ ]
        self . _window_create = None
        self . _delete = None
        self . _mark_unset = None
    def configure ( self , ** kw_args ) :
        self . _configure = kw_args
    def insert ( self , * args ) :
        self . _insert = list ( args )
    def mark_set ( self , name , pos ) :
        self . _mark_call_history += [ [ text_fake . mark_set , name , pos ] ]
    def mark_gravity ( self , name , gravity ) :
        self . _mark_call_history += [ [ text_fake . mark_gravity , name , gravity ] ]
    def mark_unset ( self , name ) :
        self . _mark_unset = name
    def window_create ( self , pos , _fake_arg = None , window = None ) :
        self . _window_create = [ pos , window ]
    def delete ( self , * args ) :
        self . _delete = list ( args )

class tkinter_fake :
    def __init__ ( self ) :
        self . _text_collection = [ ]
        self . NORMAL = None
        self . DISABLED = None
        self . END = None
        self . INSERT = None
        self . LEFT = None
    def Tk ( self ) :
        return application_window_fake ( )
    def Text ( self , master ) :
        text = text_fake ( )
        self . _text_collection += [ text ]
        return text

class mediator_fake :
    def __init__ ( self ) :
        self . _gui_create_application_window_reply = None
        self . _gui_create_text_reply = None
    def gui_create_application_window_reply ( self , window ) :
        self . _gui_create_application_window_reply = window
    def gui_create_text_reply ( self , text ) :
        self . _gui_create_text_reply = text 

class gui_text_tests :
    'gui_text'
    def __init__ ( self , test ) :
        self . _test = test
        self . _assistant = gui_create_widget_test_assistant ( test )
        self . _tkinter = tkinter_fake ( )
        self . _mediator = mediator_fake ( )
        self . _gui = gui ( mediator = self . _mediator , tkinter = self . _tkinter , tkfont = None , scheduler = None )
    def test_gui_create_text ( self ) :
        self . _assistant . check_gui_create_arbitrary_element ( 'text' )
    def test_gui_create_text_args ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_args ( 'text' )
    def test_gui_create_text_persistance ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_persistance ( 'text' )
    def test_gui_create_text_destruction ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_destruction ( 'text' )
    def test_gui_create_text_encapsulation ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_encapsulation ( 'text' )
    def test_gui_create_text_child ( self ) :
        self . _assistant . check_gui_create_arbitrary_element_child ( 'text' )
    def test_gui_enable_text_edit ( self ) :
        self . _tkinter . NORMAL = 'my normal'
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_text_request ( window )
        text = self . _mediator . _gui_create_text_reply
        self . _gui . gui_enable_text_edit ( text )
        self . _test . assume_equal \
            ( self . _tkinter . _text_collection [ 0 ] . _configure 
            , { 'state' : 'my normal' }
            )
    def test_gui_disable_text_edit ( self ) :
        self . _tkinter . DISABLED = 'my disabled'
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_text_request ( window )
        text = self . _mediator . _gui_create_text_reply
        self . _gui . gui_disable_text_edit ( text )
        self . _test . assume_equal \
            ( self . _tkinter . _text_collection [ 0 ] . _configure 
            , { 'state' : 'my disabled' }
            )
    def test_gui_add_string_to_text_widget ( self ) :
        self . _tkinter . END = 'my end'
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_text_request ( window )
        text = self . _mediator . _gui_create_text_reply
        self . _gui . gui_add_string_to_text_widget ( text , 'my string' )
        self . _test . assume_equal ( self . _tkinter . _text_collection [ 0 ] . _insert , [ 'my end' , 'my string' ] )
    def test_gui_add_mark_to_text_widget ( self ) :
        self . _tkinter . INSERT = 'my insert'
        self . _tkinter . LEFT = 'my left'
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_text_request ( window )
        text = self . _mediator . _gui_create_text_reply
        self . _gui . gui_add_mark_to_text_widget ( text , 'my mark' )
        self . _test . assume_equal ( self . _tkinter . _text_collection [ 0 ] . _mark_call_history ,
            [ [ text_fake . mark_set , 'my mark' , 'my insert' ]
            , [ text_fake . mark_gravity , 'my mark' , 'my left' ]
            ] )
    def test_gui_add_widget_to_text_widget ( self ) :
        self . _tkinter . END = 'my end'
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_text_request ( window )
        text = self . _mediator . _gui_create_text_reply
        self . _gui . gui_create_text_request ( window )
        widget = self . _mediator . _gui_create_text_reply
        self . _gui . gui_add_widget_to_text_widget ( text , widget )
        self . _test . assume_equal ( self . _tkinter . _text_collection [ 0 ] . _window_create , 
            [ 'my end' 
            , self . _tkinter . _text_collection [ 1 ]
            ] )
    def test_gui_remove_widget_from_text_widget ( self ) :
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_text_request ( window )
        text = self . _mediator . _gui_create_text_reply
        self . _gui . gui_create_text_request ( window )
        widget = self . _mediator . _gui_create_text_reply
        self . _gui . gui_remove_widget_from_text_widget ( text , widget )
        self . _test . assume_equal ( self . _tkinter . _text_collection [ 0 ] . _delete , [ self . _tkinter . _text_collection [ 1 ] ] )
    def test_gui_remove_mark_from_text_widget ( self ) :
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_text_request ( window )
        text = self . _mediator . _gui_create_text_reply
        self . _gui . gui_remove_mark_from_text_widget ( text , 'my mark' )
        self . _test . assume_equal ( self . _tkinter . _text_collection [ 0 ] . _mark_unset , 'my mark' )
    def test_gui_delete_text_from_mark_to_end_of_text_widget ( self ) :
        self . _tkinter . END = 'my end'
        self . _gui . gui_create_application_window_request ( )
        window = self . _mediator . _gui_create_application_window_reply
        self . _gui . gui_create_text_request ( window )
        text = self . _mediator . _gui_create_text_reply
        self . _gui . gui_delete_text_from_mark_to_end_of_text_widget ( text , 'my mark' )
        self . _test . assume_equal ( self . _tkinter . _text_collection [ 0 ] . _delete , [ 'my mark' , 'my end' ] )
